package tree.tree2.symmetry.isSame;

import tree.TreeNode;

/**
 * @ClassName IsSymmetric1
 * @Description TODO
 * @Author lenovo
 * @Date 2023-04-24 9:46
 * @Version 1.0
 * @Comment Magic. Do not touch.
 * If this comment is removed. the program will blow up
 */
public class IsSymmetric1 {
    /**
     * isSymmetric1
     * <p>
     * 101. 对称二叉树
     * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
     *     1
     * 2       2
     */

    public boolean isSymmetric(TreeNode root) {

        return judgeIsSymmetric(root.left, root.right);
    }

    private boolean judgeIsSymmetric(TreeNode left, TreeNode right) {

        if (left != null && right == null) {
            return false;
        }
        if (left == null && right!=null) {
            return false;
        }
        if(left == null && right == null){
            return true;
        }
        if(left.val!=right.val){
            return false;
        }

        boolean outIsSame = judgeIsSymmetric(left.left, right.right);
        boolean inIsSame = judgeIsSymmetric(left.right,right.left);
        return outIsSame&&inIsSame;
    }

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1);
        treeNode.left = new TreeNode(2);
        treeNode.right = new TreeNode(2);
        IsSymmetric1 isSymmetric1 = new IsSymmetric1();
        System.out.println(isSymmetric1.isSymmetric(treeNode));
//        Float aFloat = Float.valueOf("100.0");
//        System.out.println(aFloat);
    }
}